//
//  ZDModifyPasswordController.m
//  特种车调度
//
//  Created by 陈宇 on 15/8/20.
//
//

#import "ZDModifyPasswordController.h"
#import "BMAccountManager.h"

@interface ZDModifyPasswordController ()

@property (weak, nonatomic) IBOutlet UITextField *oldTextfield;
@property (weak, nonatomic) IBOutlet UITextField *n1Textfield;
@property (weak, nonatomic) IBOutlet UITextField *n2Textfield;

- (IBAction)okAction:(id)sender;
@end

@implementation ZDModifyPasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)okAction:(id)sender {
    NSString *old = _oldTextfield.text;
    NSString *new1 = _n1Textfield.text;
    NSString *new2 = _n2Textfield.text;
    
    if ([BMUtils isEmptyString:old] || [BMUtils isEmptyString:new1]) {
        [self showHint:@"请输入6-16为密码"];
        return;
    }
    
    if (![new1 isEqualToString:new2]) {
        [self showHint:@"两次密码输入不一致!"];
        return;
    }
    
    BMRequest *request = [BMRequest requestWithPath:@"updatePassword.htm"];
    request.params = @{(kRoleType ? @"disId" : @"ownId"): @([BMAccountManager sharedInstance].user.ID), @"oldPwd": old, @"newPwd": new1};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            [[BMAccountManager sharedInstance] logout];
            [self.navigationController popToRootViewControllerAnimated:YES];
        } else {
            [self showHint:@"修改密码失败"];
        }
    }];
}

@end
